<template>
	<view style="padding-bottom: 50rpx;">
		<page-head :title="'我的验车'" :headtype="2" :gourl="2" @closepage="backfun()"></page-head>
		<view class="tagnav"> 
			<view class="tagnavmain marginAuto">
				<!-- <view class="naveach" @click="navfun(0)" :class="navac == 0 ? 'navactive':''">全部
					<view class="naveachx"></view>
				</view> -->
				<view class="naveach" @click="navfun(1)" :class="navac == 1 ? 'navactive':''">待接单
					<view class="naveachx"></view>
				</view>
				<view class="naveach" @click="navfun(2)" :class="navac == 2 ? 'navactive':''">待验车
					<view class="naveachx"></view>
				</view>
				<view class="naveach" @click="navfun(3)" :class="navac == 3 ? 'navactive':''">已完成
					<view class="naveachx"></view>
				</view>
			</view>
		</view>
		<!-- @click="apifun.navigate('/pages/my/myvalidatexq','id='+item.id)" -->
		<view class="testlist">
			<view class="testitem marginAuto flex" v-for="(item,index) in datas" :key="index" >
				<view class="cardeachbmsg"> 
					<view class="cardeachbmsg-name flex">
						<view class="cardeachbmsg-namen flex">
							<view class="carname ellipsis01">{{ item.username }}</view>
							<view class="cartype">{{ item.source_text }}</view>
						</view>
						<view class="cardeachbmsg-namestatus mainColor">{{ item.order_status_txt }}</view>
					</view>
					<view class="cardeachbmsg-jl flex">
						<view class="jltime">{{ item.brand }} / {{ item.car_type_txt }} / {{ item.condition_txt }}</view>
					</view>
					<view class="cardeachbmsg-jl flex">
						<view class="jltime">套餐名称：{{ item.menu_name }}</view>
					</view>
					<view class="cardeachbmsg-jl flex">
						<!-- <view class="jlq mainBg baiColor" v-if="item.pay_type == 2">先验后付</view> -->
						<view class="jltime">验车时间：{{ $uv.timeFormat(item.reserve_time,'yyyy-mm-dd hh:MM:ss') }}</view>
					</view>
					
					<view class="cardeachbmsg-site flex">
						<view class="site flex" style="width:55%;">
							<uv-icon name="map" style="margin-top:4rpx;" color="#1686F8" size="16"></uv-icon>
							<view class="mainColor ellipsis01" style="width:90%;margin-left:5rpx;">{{ item.address }}</view>
						</view>
					</view>
					<!-- status：1待派单 2待确认 3待服务 4待评价 5已完成 6已取消 7待验券 8待上传券码   is_trial  1体验课 source_id 1 平台下单否则后台录入-->
					<view class="cardeachbmsg-site flex" style="width:100%;justify-content: flex-end;">
						<view class="cardbtn flex" v-if="navac == 1">
							<view class="cardbtneach mainColor" style="background:#ECF8FF;" @click.stop="$refs.closepup.open(),acitem=item,acindex=index">取消</view>
							<!-- <view class="cardbtneach mainBg baiColor" @click.stop="apifun.navigate('/pages/my/myvalidatexq','id='+item.id)">支付</view> -->
						</view>
						<view class="cardbtn flex" v-if="navac == 2">
							<view class="cardbtneach mainBg baiColor" v-if="item.source_id == 1" @click.stop="$refs.endorderpup.open(),acitem=item,acindex=index">完成</view>
							<view class="cardbtneach mainBg baiColor" v-if="item.source_id != 1" @click.stop="$refs.isupqcode.open(),upqcodetxt='',volumesrc='',acitem=item,acindex=index">上传券码</view>
						</view>
						<view class="cardbtn flex" v-if="navac == 3">
							<view class="cardbtneach mainColor" style="background:#ECF8FF;" @click.stop="$refs.delpup.open(),acitem=item,acindex=index">删除</view>
							<view class="cardbtneach mainBg baiColor" @click.stop="apifun.navigate('/pages/my/result','id='+item.id)">查看验车报告</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 弹窗 -->
		<uv-popup ref="closepup" bgColor="none" round="20">
			<view class="closetest">
				<image class="closetestbg" :src="apifun.serveimg+'closetestbg.png'" mode=""></image>
				<view class="closetesttitle">取消</view>
				<view class="closetestdoc">确认取消此订单吗？</view>
				<view class="closetestbtn flex">
					<view class="closetestbtne mainColor" style="background: #ffffff;" @click="$refs.closepup.close()">取消</view>
					<view class="closetestbtne mainBg baiColor" @click="closeorderfun">确定</view>
				</view>
			</view>
		</uv-popup>
		<uv-popup ref="delpup" bgColor="none" round="20">
			<view class="closetest">
				<image class="closetestbg" :src="apifun.serveimg+'closetestbg.png'" mode=""></image>
				<view class="closetesttitle">删除</view>
				<view class="closetestdoc">确认删除此订单吗？</view>
				<view class="closetestbtn flex">
					<view class="closetestbtne mainColor" style="background: #ffffff;" @click="$refs.delpup.close()">取消</view>
					<view class="closetestbtne mainBg baiColor" @click="delorderfun">确定</view>
				</view>
			</view>
		</uv-popup>
		<uv-popup ref="endorderpup" bgColor="none" round="20">
			<view class="closetest">
				<image class="closetestbg" :src="apifun.serveimg+'closetestbg.png'" mode=""></image>
				<view class="closetesttitle">完成订单</view>
				<view class="closetestdoc">确认完成此订单吗？</view>
				<view class="closetestbtn flex">
					<view class="closetestbtne mainColor" style="background: #ffffff;" @click="$refs.delpup.close()">取消</view>
					<view class="closetestbtne mainBg baiColor" @click="endorder()">完成</view>
				</view>
			</view>
		</uv-popup>
		<uv-popup ref="isupqcode" bgColor="none" round="20">
			<view class="closetest" style="height: 800rpx;background: #fff;">
				<image class="closetestbg" style="height:600rpx;" :src="apifun.serveimg+'closetestbg.png'" mode=""></image>
				<view class="closetesttitle">上传券码</view>
				<view class="closetestdoc marginAuto" style="width:90%;height:80rpx;border-radius: 20rpx;margin-top: 20rpx;background:#fff;">
					<input style="height:80rpx;line-height: 80rpx;" class="closetestdocinput" type="text" placeholder="请输入券码" v-model="upqcodetxt"/>
				</view>
				<view class="uploadvolume marginAuto flex" style="margin-top: 20rpx;" @click="uploadvolume">
					<view class="uploadvolumeicon">
						<uv-icon  name="photo" size="40" color="#ccc"></uv-icon>
					</view>
					<image :src="apifun.URLimg+volumesrc" mode="aspectFill"></image>
				</view>
				<view class="closetestbtn flex">
					<view class="closetestbtne mainColor" style="background: #ffffff;" @click="$refs.isupqcode.close()">取消</view>
					<view class="closetestbtne mainBg baiColor" @click="upqcodefun()">确定</view>
				</view>
			</view>
		</uv-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				apifun:this.apifun,
				page:1,
				navac:1,
				acitem:{},
				acindex:'',
				datas:[],
				upqcodetxt:'',
				volumesrc:''
			};
		},
		onLoad() {
			this.initData()
		},
		methods: {
			endorder(){  //  完成订单
				let sendData = {
					order_id:this.acitem.id,
				};
				this.apifun.unirequest('/api/verifyCart/completeOrder','post',sendData,(res)=>{
					if(res.code === 200){
						let datas = res.data;
						this.datas.splice(this.acindex,1);
						this.$refs.endorderpup.close();
					}else{
						this.apifun.toast(res.msg)
					}
				})
			},
			upqcodefun(){  //  上传券码
				let sendData = {
					order_id:this.acitem.id,
					code:this.upqcodetxt,
					img:this.volumesrc
				};
				if(this.upqcodetxt == '' && this.volumesrc == ''){
					this.apifun.toast('请输入券码')
					return false
				}
				this.apifun.unirequest('/api/partnerDrive/uploadCode','post',sendData,(res)=>{
					if(res.code === 200){
						let datas = res.data;
						this.datas.splice(this.acindex,1);
						this.$refs.isupqcode.close();
					}else{
						this.apifun.toast(res.msg)
					}
				})
			},
			initData(){
				let sendData = {
					page:this.page,
					limit:this.apifun.limit,
					status:this.navac
				};
				this.apifun.unirequest('/api/verifyCart/getOrderList','post',sendData,(res)=>{
					if(res.code === 200){
						let datas = res.data;
						if(datas.data.length <= 0){
							this.page--;
							return false
						};
						this.datas = [...this.datas,...datas.data]
					}else{
						this.apifun.toast(res.msg)
					}
				})
			},
			qrcodefun(item,index){  // 券码  【作废】
				uni.setStorageSync('qrcode',item.qrcode_url);
				setTimeout(()=>{
					this.apifun.navigate('/pages/my/mytestqrcode')
				},300)
			},
			closeorderfun(){  // 取消
				let sendData = {
					order_id:this.acitem.id
				};
				this.apifun.unirequest('/api/verifyCart/cancelOrder','post',sendData,(res)=>{
					if(res.code === 200){
						let datas = res.data;
						this.datas.splice(this.acindex,1);
						this.$refs.closepup.close();
					}else{
						this.apifun.toast(res.msg)
					}
				})
			},
			delorderfun(){  // 删除
				let sendData = {
					order_id:this.acitem.id
				};
				this.apifun.unirequest('/api/verifyCart/delOrder','post',sendData,(res)=>{
					if(res.code === 200){
						let datas = res.data;
						this.datas.splice(this.acindex,1);
						this.$refs.delpup.close()
					}else{
						this.apifun.toast(res.msg)
					}
				})
			},
			uploadvolume(){
				this.apifun.uploadFileimg((res)=>{
					if(res.code == 200){
						this.volumesrc = res.data.src;
					}
				})
			},
			navfun(type){
				if(type == this.navac) return false
				this.navac = type;
				this.page = 1;
				this.datas = [];
				this.initData();
			},
			backfun(){
				uni.switchTab({
					url:'/pages/tabbar/my'
				})
			}
		},
		onPullDownRefresh() {
			this.page = 1;
			this.datas = [];
			this.initData();
			uni.stopPullDownRefresh();
		},
		onReachBottom() {
			this.page++;
			this.initData()
		},
	};
</script>

<style scoped lang="scss">
	@import '@/public/alert.scss';
	page{ 
		background: #F7F7F7;
	}
	.tagnav{
		position:sticky;
		top: 0;
		width: 100%;
		padding:16rpx 0rpx 24rpx;
		background: #fff;
		.tagnavmain{
			width:85%;
			display: flex;
			justify-content: space-between;
			.naveach {
				position: relative;
				color: #999999;
				font-size:30rpx;
				text-align: center;
				font-weight: 600;
				.naveachx {
					position: absolute;
					bottom: -10rpx;
					left: 50%;
					background: #fff;
					width: 50rpx;
					margin-left: -25rpx;
					height: 6rpx;
					border-radius: 100rpx;
					transition: background .5s;
				}
			}
			.navactive {
				color:#333333;
				
				.naveachx {
					background: #2AB4FF;
				}
			}
		}
	}
	.testitem{
		width: 650rpx;
		padding: 20rpx;
		background: #fff;
		border-radius: 20rpx;
		margin-top: 20rpx;
		.cardeachbmsg{
			flex: 1;
			margin-left: 20rpx;
			.cardeachbmsg-name{
				color: #333333;
				font-size:30rpx;
				margin-top:15rpx;
				line-height: 50rpx;
				justify-content: space-between;
				.cardeachbmsg-namen{
					width: 85%;
					.carname{
						width:200rpx;
					}
					.cartype{
						display: inline-block;
						padding:0 10rpx;
						background:#FFF1E2;
						color:#FF720C;
						font-size:20rpx;
						border-radius: 10rpx;
						height: 40rpx;
						line-height: 40rpx;
						margin-left: 10rpx;
					}
				}
				.cardeachbmsg-namestatus{
					font-size: 26rpx;
				}
			}
			.cardeachbmsg-jl{
				padding: 10rpx 0;
				font-size: 26rpx;
				line-height:40rpx;
				.jlq{
					display: inline-block;
					padding:0 10rpx;
					background:#FFF1E2;
					color:#FF720C;
					font-size:20rpx;
					border-radius:6rpx;
					height: 40rpx;
					line-height: 40rpx;
					margin-right: 10rpx;
				}
			}
			.cardeachbmsg-site{
				justify-content: space-between;
				.site{
					font-size: 24rpx;
					line-height: 54rpx;
				}
				.cardbtn{
					.cardbtneach{
						padding: 0 30rpx;
						height: 54rpx;
						line-height: 54rpx;
						font-size:28rpx;
						text-align: center;
						border-radius: 100rpx;
						margin-left:20rpx;
					}
				}
			}
			
		}
	}
	.uploadvolume{
		position: relative;
		z-index: 10;
		width:350rpx;
		height:350rpx;
		background: #fff;
		border-radius:20rpx;
		.uploadvolumeicon{
			position: absolute;
			left: 50%;
			top: 50%;
			margin-top: -30rpx;
			margin-left: -30rpx;
		}
		image{
			position: absolute;
			top: 0;
			left: 0;
			z-index: 10;
			width: 100%;
			height: 100%;
			
		}
	}
</style>